package cn.xiaoliu.order.controller;

import cn.xiaoliu.basic.utils.AjaxResult;
import cn.xiaoliu.basic.utils.LoginContext;
import cn.xiaoliu.basic.utils.PageList;
import cn.xiaoliu.order.domain.AdoptOrder;
import cn.xiaoliu.order.domain.ProductOrder;
import cn.xiaoliu.order.query.ProductOrderQuery;
import cn.xiaoliu.order.service.IProductOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {

    @Autowired
    private IProductOrderService productOrderService;
    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){

        try{
            String payData = productOrderService.submit(params, LoginContext.getLogininfo(request));
            System.out.println(payData);
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }
    //查询平台管理员订单或者店铺订单   根据shopid为空不为空判断是平台还是店铺
    @PostMapping("/admin")
    public PageList<ProductOrder> queryAdmin(@RequestBody ProductOrderQuery query, HttpServletRequest request){
        return productOrderService.queryAdmin(query, LoginContext.getLogininfo(request));
    }

    //详情展示
    @GetMapping("{id}")
    public ProductOrder queryById(@PathVariable("id") Long id){

        return productOrderService.queryById(id);
    }
}
